const db = uniCloud.database();

module.exports = {
	_before: function() { // 通用预处理器
	},
	categories() {
		return db.collection('category').get();
	},
	notify() {
		return db.collection('notify').where({
			isShow: true
		}).get();
	},
	goods({
		isHot = false,
		isNew = false,
		goodsComment = false,
		sales = false
	}) {
		let goods = db.collection('goods');
		let where = {};
		if (isHot) where.is_hot = true;
		if (isNew) where.is_new = true;
		goods = goods.where(where);
		if(goodsComment) goods = goods.orderBy('comment_count','desc')
		if(sales) goods = goods.orderBy('month_sell_count','desc')
		
		return goods.get();
	}
}
